package com.yuexun.dhdoctor.module.meetingNew.ui;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.base.BaseEntity;
import com.yuexun.dhdoctor.base.BaseKJActivity;
import com.yuexun.dhdoctor.base.model.impl.HelpModel;
import com.yuexun.dhdoctor.base.presenter.impl.HelpPresent;
import com.yuexun.dhdoctor.base.ui.IHelpView;
import com.yuexun.dhdoctor.config.AppConfig;
import com.yuexun.dhdoctor.module.email.adapter.MailFileAdapter;
import com.yuexun.dhdoctor.module.email.bean.MailFileBean;
import com.yuexun.dhdoctor.module.email.bean.MailFileDataBean;
import com.yuexun.dhdoctor.module.email.bean.UploadBean;
import com.yuexun.dhdoctor.module.email.model.impl.UploadModel;
import com.yuexun.dhdoctor.module.email.presenter.impl.UploadPresenter;
import com.yuexun.dhdoctor.module.email.ui.view.IUploadView;
import com.yuexun.dhdoctor.module.meeting.ui.Act_MeetingCheck;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewCheckStateBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewDetailBean;
import com.yuexun.dhdoctor.module.meetingNew.bean.MeetingNewSignStateEnumBean;
import com.yuexun.dhdoctor.module.meetingNew.model.impl.MeetingNewDetailModel;
import com.yuexun.dhdoctor.module.meetingNew.model.impl.MeetingNewModel;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewAbsencePresenter;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewCheckByQrCodePresenter;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewDetailPresenter;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewUpdatePresenter;
import com.yuexun.dhdoctor.module.meetingNew.presenter.impl.MeetingNewUpdateStatusPresenter;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewAbsenceView;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewCheckByQrCodeView;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewDetailView;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewUpdateStatusView;
import com.yuexun.dhdoctor.module.meetingNew.ui.view.IMeetingNewUpdateView;
import com.yuexun.dhdoctor.util.GetPathFromUri4kitkat;
import com.yuexun.dhdoctor.widget.ActionSheetDialog;
import com.yuexun.dhdoctor.widget.ClickOneDialog;
import com.yuexun.dhdoctor.widget.FixedSwipeListView;
import com.yuexun.dhdoctor.widget.LoadingDialog;
import com.yuexun.dhdoctor.widget.ModelAddViewNew;
import com.yuexun.dhdoctor.widget.ToastDialog;
import com.yuexun.dhdoctor.widget.UploadDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Act_MeetingNew_Detail extends BaseKJActivity implements IMeetingNewDetailView, IHelpView, IUploadView,
        IMeetingNewUpdateView, IMeetingNewUpdateStatusView, IMeetingNewCheckByQrCodeView, IMeetingNewAbsenceView {

    @Bind(R.id.title_tv)
    TextView tvTitle;
    @Bind(R.id.right)
    TextView meetingRightTv;
    @Bind(R.id.right_edit)
    TextView rightEdit;
    @Bind(R.id.tv_code)
    TextView tvCode;

    @Bind(R.id.tv_detail_from)
    TextView tvFromName;
    @Bind(R.id.tv_detail_jobnum)
    TextView tvFromJobNum;
    @Bind(R.id.tv_detail_department)
    TextView tvFromDepartment;
    @Bind(R.id.tv_detail_date)
    TextView tvFromDate;

    @Bind(R.id.ll_ready_content)
    LinearLayout llReadyContent;
    @Bind(R.id.tv_ready_content)
    TextView tvReadyContent;
    @Bind(R.id.ll_ready_person)
    LinearLayout llReadyPerson;
    @Bind(R.id.tv_ready_person)
    TextView tvReadyPerson;

    @Bind(R.id.ll_model_view)
    LinearLayout llModelView;
    @Bind(R.id.model_view)
    LinearLayout modelView;

    @Bind(R.id.tv_meeting_theme)
    TextView tvMeetingTheme;
    @Bind(R.id.tv_meeting_date)
    TextView tvMeetingDate;
    @Bind(R.id.tv_meeting_location)
    TextView tvMeetingLocation;
    @Bind(R.id.tv_host)
    TextView tvHost;
    @Bind(R.id.tv_clerk)
    TextView tvClerk;
    @Bind(R.id.tv_participant)
    TextView tvParticipant;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.flv_file)
    FixedSwipeListView flvFile;

    @Bind(R.id.ll_edit_material)
    LinearLayout llEditMaterial;
    @Bind(R.id.flv_material)
    FixedSwipeListView flvMaterial;

    @Bind(R.id.ll_edit_record)
    LinearLayout llEditRecord;
    @Bind(R.id.flv_attachment)
    FixedSwipeListView flvAttachment;

    @Bind(R.id.tv_error)
    TextView tvError;

    @Bind(R.id.btn_sign_in)
    Button btnSignIn;
    @Bind(R.id.btn_status)
    Button btnStatus;

    @Bind(R.id.tv_other_member)
    TextView tvOtherMember;
    @Bind(R.id.ll_other_member)
    LinearLayout llOtherMember;
    @Bind(R.id.tv_meeting_type)
    TextView tvMeetingType;

    //缺勤
    @Bind(R.id.tv_absence_content)
    TextView tvAbsenceContent;
    @Bind(R.id.ll_absence_content)
    LinearLayout llAbsenceContent;
    @Bind(R.id.absence_content_edt)
    EditText absenceContentEdt;
    @Bind(R.id.ll_absence_content_edt)
    RelativeLayout llAbsenceContentEdt;
    @Bind(R.id.absence_content_sumbit)
    TextView absenceContentSumbit;


    private String meetingId;
    //二维码全数据
    private String resultString;

    //0:展示详情 1:直接签到
    private int type;
    //1：我收到的 2：我发起的
    private int TAG;
    //当前会议状态
    private int meetingStatus;
    //1：其他 2：我缺勤的
    private int TAG_ABENCE;


    private UploadDialog uploadDialog;
    private UploadPresenter presenter_upload;
    private HelpPresent helpPresent;
    private MeetingNewDetailPresenter presenter;
    private MeetingNewUpdatePresenter updatePresenter;
    private MeetingNewUpdateStatusPresenter updateStatusPresenter;
    private MeetingNewCheckByQrCodePresenter checkByQrCodePresenter;
    private MeetingNewAbsencePresenter absencePresenter;

    private MeetingNewDetailBean meetingDetailBeanDate;

    //会议材料
    private MailFileAdapter fileMaterialAdapter;
    private ArrayList<MailFileDataBean> fileMaterialData = new ArrayList<>();
    //会议纪要
    private MailFileAdapter mailRecordAdapter;
    private ArrayList<MailFileDataBean> mailRecordData = new ArrayList<>();
    //会议附件
    private MailFileAdapter mailFileAdapter;
    private ArrayList<MailFileDataBean> mailFileData = new ArrayList<>();

    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private SimpleDateFormat daformatter = new SimpleDateFormat("MM-dd HH:mm");
    private SimpleDateFormat dateformatter = new SimpleDateFormat("yyyy-MM-dd");
    private SimpleDateFormat timeformatter = new SimpleDateFormat("HH:mm");

    private LoadingDialog loadingDialog;
    private ClickOneDialog clickOneDialog;
    private ClickOneDialog errorDialog;

    //新版会议：展示二维码、有准备人员、与会人员冲突
    private boolean isNewMeeting = false;

    //附件原路径
    private String img_path;

    //1会议材料  2会议纪要
    private int fileType = 1;

    private boolean ISNEWREASE = false;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_meetingnew_detail);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        tvTitle.setText("会议详情");
        meetingRightTv.setText("签到记录");
        loadingDialog = new LoadingDialog(this);
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.show();
        uploadDialog = new UploadDialog(this);
        presenter_upload = new UploadPresenter(new UploadModel(), this);
        presenter = new MeetingNewDetailPresenter(new MeetingNewDetailModel(), this);
//        deletePresenter = new MeetingNewDeletePresenter(new MeetingNewModel(), this);
        updatePresenter = new MeetingNewUpdatePresenter(new MeetingNewModel(), this);
        updateStatusPresenter = new MeetingNewUpdateStatusPresenter(new MeetingNewModel(), this);
        checkByQrCodePresenter = new MeetingNewCheckByQrCodePresenter(new MeetingNewModel(), this);
        absencePresenter = new MeetingNewAbsencePresenter(new MeetingNewModel(), this);
        helpPresent = new HelpPresent(new HelpModel(), this);
        meetingId = getIntent().getExtras().getString("meetingId");
        type = getIntent().getExtras().getInt("type");
        TAG = getIntent().getExtras().getInt("TAG", 1);
        TAG_ABENCE = getIntent().getExtras().getInt("TAG_ABENCE", 1);

        if (getIntent().getExtras().getString("resultString") != null) {
            resultString = getIntent().getExtras().getString("resultString");
        }

        clickOneDialog = new ClickOneDialog(this).builder().setContent("总纪要容量过大，请处理后提交!")
                .setCancelable(false).setCanceledOnTouchOutside(false);
        clickOneDialog.setCallBack(new ClickOneDialog.ICallBack() {
            @Override
            public void sureCallback(String content) {
                clickOneDialog.dismiss();
            }
        });

        Bundle bun = getIntent().getExtras();
        if (bun != null) {
            Set<String> keySet = bun.keySet();
            for (String key : keySet) {
                String value = bun.getString(key);
                if (key.equals("meetingId")) {
                    meetingId = value;
                    initP();
                }
            }
        }

        isNewMeeting = true;
        llReadyContent.setVisibility(View.VISIBLE);
        llReadyPerson.setVisibility(View.VISIBLE);

        llOtherMember.setVisibility(View.VISIBLE);


        //我发起的
        if (TAG == 2) {
            btnSignIn.setVisibility(View.GONE);
            btnStatus.setVisibility(View.VISIBLE);
            meetingRightTv.setVisibility(View.GONE);
            rightEdit.setVisibility(View.VISIBLE);

            llEditMaterial.setVisibility(View.VISIBLE);
            llEditRecord.setVisibility(View.VISIBLE);

            if (isNewMeeting) {
                tvCode.setVisibility(View.VISIBLE);
            } else {
                tvCode.setVisibility(View.GONE);
            }
        }


        absenceContentEdt.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    private void initP() {
        if (TextUtils.isEmpty(meetingId)) {
            Toast.makeText(aty, "会议详请求失败,请稍后再试", Toast.LENGTH_SHORT).show();
            return;
        }

        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("meetingId", meetingId);
        presenter.getMeetingDetail(params);
    }


    @Override
    @OnClick({R.id.back, R.id.right, R.id.tv_code, R.id.btn_sign_in,
            R.id.right_edit, R.id.ll_edit_material, R.id.ll_edit_record,
            R.id.btn_status, R.id.absence_content_sumbit})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.right:
                Intent resultIntent = new Intent(this, Act_MeetingNew_Sign.class);
                Bundle bundle = new Bundle();
                bundle.putString("meetingId", meetingId);
                resultIntent.putExtras(bundle);
                startActivity(resultIntent);
                break;
            case R.id.tv_code:
                Intent codeIntent = new Intent(this, Act_MeetingNew_Code.class);
                codeIntent.putExtra("meeting", meetingDetailBeanDate);
                codeIntent.putExtra("qrcode", meetingDetailBeanDate.getQrCodeAddress());
                codeIntent.putExtra("refreshTime", meetingDetailBeanDate.getRefreshTime());
                startActivity(codeIntent);
                break;
            case R.id.btn_sign_in:
                try {
                    long startTime = formatter.parse(meetingDetailBeanDate.getStarttime()).getTime();
                    if (System.currentTimeMillis() > startTime) {
                        Intent intent = new Intent(aty, Act_MeetingCheck.class);
                        intent.putExtra("type", 0);
                        startActivityForResult(intent, 1);
                    } else {
                        ViewInject.toast("签到时间会议时间与不符合！");
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.right_edit:
                /*Intent intent = new Intent(this, Act_MeetingNew_Edit.class);
                Bundle bundle_1 = new Bundle();
                bundle_1.putSerializable("meetingDetail", meetingDetailBeanDate);
                bundle_1.putSerializable("attachmentFile", mailFileData);
                bundle_1.putSerializable("recordFile", mailRecordData);
                intent.putExtras(bundle_1);
                startActivityForResult(intent, 1);*/
                ApiEdit();
                break;
            case R.id.ll_edit_material:
                selectFile(1);
                break;
            case R.id.ll_edit_record:
                selectFile(2);
                break;
            case R.id.btn_status:
                showStatusDialog();
                break;
            case R.id.absence_content_sumbit:
                if (absenceContentEdt.getText().toString().length() > 0) {
                    loadingDialog.show();
                    ApiForCreateAbsence(absenceContentEdt.getText().toString());
                } else {
                    ViewInject.toast("请输入缺勤原因");
                }
                break;
        }
    }

    //选择会议状态
    private void showStatusDialog() {
        new ActionSheetDialog(aty)
                .builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true)
                .addSheetItem("正常", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                btnStatus.setText("正常");
                                meetingStatus = 1;
                                ApiForMeetingStatus();
                            }
                        })
                .addSheetItem("取消", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                btnStatus.setText("取消");
                                meetingStatus = 2;
                                ApiForMeetingStatus();
                            }
                        })
                .addSheetItem("提前", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                btnStatus.setText("提前");
                                meetingStatus = 3;
                                ApiForMeetingStatus();
                            }
                        })
                .addSheetItem("延迟", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                btnStatus.setText("延迟");
                                meetingStatus = 4;
                                ApiForMeetingStatus();
                            }
                        }).show();
    }

    //创建缺勤
    private void ApiForCreateAbsence(String content) {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("meetingId", meetingDetailBeanDate.getMeetingId());
        params.put("absenceReason", content);
        absencePresenter.createMeetingAbsence(params);
    }

    //更新缺勤
    private void ApiForUpdateAbsence(String content) {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("meetingId", meetingDetailBeanDate.getMeetingId());
        params.put("absenceReason", content);
        absencePresenter.updateMeetingAbsence(params);
    }

    //更新会议状态
    private void ApiForMeetingStatus() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("meetingId", meetingDetailBeanDate.getMeetingId());
        params.put("meetingFlag", meetingStatus + "");
        updateStatusPresenter.updateStatus(params);
    }

    //修改保存会议
    private void ApiEdit() {
        String[] strPeopleIdArr = new String[meetingDetailBeanDate.getParticipantIds().size()];
        for (int i = 0; i < meetingDetailBeanDate.getParticipantIds().size(); i++) {
            strPeopleIdArr[i] = meetingDetailBeanDate.getParticipantIds().get(i);
        }

        String[] strReadyPeopleIdArr = new String[meetingDetailBeanDate.getReadyIds().size()];
        for (int i = 0; i < meetingDetailBeanDate.getReadyIds().size(); i++) {
            strReadyPeopleIdArr[i] = meetingDetailBeanDate.getReadyIds().get(i);
        }

        String[] strDeptIdArr = new String[meetingDetailBeanDate.getSignDeptList().size()];
        String[] strDeptSignCountArr = new String[meetingDetailBeanDate.getSignDeptList().size()];
        for (int i = 0; i < meetingDetailBeanDate.getSignDeptList().size(); i++) {
            strDeptIdArr[i] = meetingDetailBeanDate.getSignDeptList().get(i).getDepartmentId() + "";
            strDeptSignCountArr[i] = meetingDetailBeanDate.getSignDeptList().get(i).getSignTotalCount();
        }

        StringBuilder strRecordFile = new StringBuilder();
        for (int i = 0; i < mailRecordData.size(); i++) {
            strRecordFile.append(mailRecordData.get(i).getFileUuid()).append(";");
        }
        StringBuilder materialFile = new StringBuilder();
        for (int i = 0; i < fileMaterialData.size(); i++) {
            materialFile.append(fileMaterialData.get(i).getFileUuid()).append(";");
        }

        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("meetingId", meetingDetailBeanDate.getMeetingId());
        params.put("meetingName", meetingDetailBeanDate.getMeetingName());
        params.put("startDatetime", meetingDetailBeanDate.getStarttime());
        params.put("endDatetime", meetingDetailBeanDate.getEndtime());
        params.put("roomId", meetingDetailBeanDate.getRoomId());
        params.put("roomName", meetingDetailBeanDate.getRoomName());
        params.put("content", meetingDetailBeanDate.getContent());
        params.put("compere", meetingDetailBeanDate.getCompere());
        params.put("clerk", meetingDetailBeanDate.getClerk());
        params.put("participant", meetingDetailBeanDate.getParticipant());
        params.put("visibleRole", meetingDetailBeanDate.getVisibleRole());
        params.put("materialUrl", materialFile.toString());
        params.put("digestUrl", strRecordFile.toString());
        params.put("fileUrl", meetingDetailBeanDate.getFileUrl());
        params.put("readyContent", meetingDetailBeanDate.getReadyContent());
        params.put("readyNames", meetingDetailBeanDate.getReadyNames());
        params.put("otherMember", meetingDetailBeanDate.getOtherMember());
        updatePresenter.updateMeeting(strPeopleIdArr, strReadyPeopleIdArr, strDeptIdArr, strDeptSignCountArr, params);
        loadingDialog.show();
    }

    @Override
    public void showMeetingDetail(BaseEntity<MeetingNewDetailBean> meetingDetailBean) {
        if (meetingDetailBean.getStatus().equals("200")) {
            meetingDetailBeanDate = meetingDetailBean.getDatas().get(0);

            //缺勤
            if (true) {
                if (meetingDetailBeanDate.getAbsenceReason().length() > 0) {
                    llAbsenceContent.setVisibility(View.VISIBLE);
                    tvAbsenceContent.setText(meetingDetailBeanDate.getAbsenceReason());
                } else {
                    if (TAG_ABENCE == 1) {
                        llAbsenceContentEdt.setVisibility(View.VISIBLE);
                    }
                }
            }

            tvFromName.setText(meetingDetailBeanDate.getCreatorName());
            tvFromJobNum.setText(meetingDetailBeanDate.getJobNum());
            tvFromDepartment.setText(meetingDetailBeanDate.getDepName());
            tvFromDate.setText(meetingDetailBeanDate.getCreateDate());

            tvMeetingTheme.setText("会议主题：" + meetingDetailBeanDate.getMeetingName());

            if (!TextUtils.isEmpty(meetingDetailBeanDate.getReadyContent())) {
                tvReadyContent.setText(meetingDetailBeanDate.getReadyContent());
            }
            if (!TextUtils.isEmpty(meetingDetailBeanDate.getReadyNames())) {
                tvReadyPerson.setText(meetingDetailBeanDate.getReadyNames());
            }

            try {
                Date start = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(meetingDetailBeanDate.getStarttime());
                Date end = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(meetingDetailBeanDate.getEndtime());

                if (dateformatter.parse(meetingDetailBeanDate.getStarttime()).equals(dateformatter.parse(meetingDetailBeanDate.getEndtime()))) {
                    tvMeetingDate.setText(daformatter.format(start) + " - " + timeformatter.format(end));
                } else {
                    tvMeetingDate.setText(daformatter.format(start) + " - " + daformatter.format(end));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
//            tvMeetingDate.setText(meetingDetailBeanDate.getStarttime() + "-" + meetingDetailBeanDate.getEndtime());
            tvMeetingLocation.setText(meetingDetailBeanDate.getRoomName());
            tvHost.setText(meetingDetailBeanDate.getCompere());
            tvClerk.setText(meetingDetailBeanDate.getClerk());
            tvParticipant.setText(meetingDetailBeanDate.getParticipant());
            tvContent.setText(meetingDetailBeanDate.getContent());

            if (TAG == 2) {     //我发起的
                meetingStatus = meetingDetailBeanDate.getMeetingFlag();
                if (meetingDetailBeanDate.getMeetingFlag() == 1) {
                    btnStatus.setText("正常");
                } else if (meetingDetailBeanDate.getMeetingFlag() == 2) {
                    btnStatus.setText("取消");
                } else if (meetingDetailBeanDate.getMeetingFlag() == 3) {
                    btnStatus.setText("提前");
                } else if (meetingDetailBeanDate.getMeetingFlag() == 4) {
                    btnStatus.setText("延迟");
                }
            } else {            //我收到的、与我相关
                if (meetingDetailBeanDate.getMeetingFlag() == 1) {
                    btnSignIn.setVisibility(View.VISIBLE);
                } else if (meetingDetailBeanDate.getMeetingFlag() == 2 ||
                        meetingDetailBeanDate.getMeetingFlag() == 3 ||
                        meetingDetailBeanDate.getMeetingFlag() == 4) {
                    btnSignIn.setVisibility(View.GONE);
                }
            }

            llOtherMember.setVisibility(View.VISIBLE);
            tvOtherMember.setText(meetingDetailBeanDate.getOtherMember());

            //附件
            mailFileData.clear();
            if (mailFileAdapter != null) {
                mailFileAdapter.notifyDataSetChanged();
            }
            if (meetingDetailBeanDate.getFileUrl() != null && !meetingDetailBeanDate.getFileUrl().isEmpty()) {
                String[] fileUrls = meetingDetailBeanDate.getFileUrl().split(";");

                for (String fileUrl : fileUrls) {
                    if (fileUrl != null && !fileUrl.isEmpty()) {
                        Map<String, String> params = new HashMap<>();
                        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        params.put("fileUuid", fileUrl);
                        helpPresent.getFileData(params);
                    }
                }
            }

            //会议纪要
            mailRecordData.clear();
            if (mailRecordAdapter != null) {
                mailRecordAdapter.notifyDataSetChanged();
            }
            if (meetingDetailBeanDate.getDigestUrl() != null && !meetingDetailBeanDate.getDigestUrl().isEmpty()) {
                String[] digestUrls = meetingDetailBeanDate.getDigestUrl().split(";");
                HelpPresent helpPresent = new HelpPresent(new HelpModel(), new IHelpView() {
                    @Override
                    public void getFileData(MailFileBean bean) {
                        mailRecordData.add(bean.getDatas().get(0));
                        if (TAG == 1) {
                            mailRecordAdapter = new MailFileAdapter(aty, mailRecordData, false);
                        } else {
                            mailRecordAdapter = new MailFileAdapter(aty, mailRecordData, true);
                        }
                        flvAttachment.setAdapter(mailRecordAdapter);
                    }
                });

                for (String digestUrl : digestUrls) {
                    if (digestUrl != null && !digestUrl.isEmpty()) {
                        Map<String, String> params = new HashMap<>();
                        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        params.put("fileUuid", digestUrl);
                        helpPresent.getFileData(params);
                    }
                }
            }

            //会议材料
            fileMaterialData.clear();
            if (fileMaterialAdapter != null) {
                fileMaterialAdapter.notifyDataSetChanged();
            }
            if (meetingDetailBeanDate.getMaterialUrl() != null && !meetingDetailBeanDate.getMaterialUrl().isEmpty()) {
                String[] materialUrls = meetingDetailBeanDate.getMaterialUrl().split(";");
                HelpPresent helpPresent = new HelpPresent(new HelpModel(), new IHelpView() {
                    @Override
                    public void getFileData(MailFileBean bean) {
                        fileMaterialData.add(bean.getDatas().get(0));
                        if (TAG == 1) {
                            fileMaterialAdapter = new MailFileAdapter(aty, fileMaterialData, false);
                        } else {
                            fileMaterialAdapter = new MailFileAdapter(aty, fileMaterialData, true);
                        }
                        flvMaterial.setAdapter(fileMaterialAdapter);
                    }
                });

                for (String materialUrl : materialUrls) {
                    if (materialUrl != null && !materialUrl.isEmpty()) {
                        Map<String, String> params = new HashMap<>();
                        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
                        params.put("fileUuid", materialUrl);
                        helpPresent.getFileData(params);
                    }
                }
            }

            tvMeetingType.setText(meetingDetailBeanDate.getConfigName());

            //模板详情
            if (meetingDetailBeanDate.getDtlList() != null && meetingDetailBeanDate.getDtlList().size() > 0) {
                llModelView.setVisibility(View.VISIBLE);
//                modelView.addView(new ModelAddViewNew(aty).createTxtView(null, "类型", meetingDetailBeanDate.getConfigName()));
                if (meetingDetailBeanDate.getDtlList() != null && meetingDetailBeanDate.getDtlList().size() > 0
                        && !meetingDetailBeanDate.getDtlList().get(0).getShowType().isEmpty()) {
                    for (int i = 0; i < meetingDetailBeanDate.getDtlList().size(); i++) {
                        modelView.addView(new ModelAddViewNew(aty).createTxtView(meetingDetailBeanDate.getDtlList().get(i), null, null));
                    }
                }
            }

            inquireSignState();
        } else if (meetingDetailBean.getStatus().equals("403") || meetingDetailBean.getStatus().equals("404")) {
            tvError.setText(meetingDetailBean.getMessage());
            tvError.setVisibility(View.VISIBLE);
            meetingRightTv.setVisibility(View.GONE);
        } else {
            ViewInject.toast(meetingDetailBean.getMessage());
        }
        loadingDialog.dismiss();
    }

    @Override
    public void showMeetingCheckState(BaseEntity<MeetingNewCheckStateBean> meetingCheckStateBean) {
        if (meetingCheckStateBean.getStatus().equals("200")) {
            MeetingNewCheckStateBean meetingCheckStateBeanDate = meetingCheckStateBean.getDatas().get(0);
            MeetingNewSignStateEnumBean signStateEnum = MeetingNewSignStateEnumBean.valueOf(meetingCheckStateBeanDate.getSignState());

            switch (signStateEnum) {
                case NO_SIGN:
                    break;
                case SIGN_IN:
                    btnSignIn.setText(signStateEnum.getDescription());
                    if (meetingDetailBeanDate.getAbsenceReason().length() > 0) {
                        llAbsenceContent.setVisibility(View.VISIBLE);
                    } else {
                        llAbsenceContent.setVisibility(View.GONE);
                        llAbsenceContentEdt.setVisibility(View.GONE);
                    }
                    break;
                case MEETING_OUT_OF_DATE:
                    btnSignIn.setText(signStateEnum.getDescription());
                    btnSignIn.setEnabled(false);
                    if (meetingDetailBeanDate.getAbsenceReason().length() > 0) {
                        llAbsenceContent.setVisibility(View.VISIBLE);
                    } else {
                        llAbsenceContent.setVisibility(View.GONE);
                        llAbsenceContentEdt.setVisibility(View.GONE);
                    }
                    break;
            }
            if (type == 1) {
                signIn(meetingId);
            }
        } else {
            ViewInject.toast(meetingCheckStateBean.getMessage());
        }
    }

    @Override
    public void showMeetingCheck(BaseEntity<String> meetingBeanCheckBean) {
        if (meetingBeanCheckBean.getStatus().equals("200")) {
            ViewInject.toast("签到成功");
            btnSignIn.setText("已签到");
//            meetingRightTv.setEnabled(false);
        } else {
            ViewInject.toast(meetingBeanCheckBean.getMessage());
        }
    }

    @Override
    public void checkByQrCode(BaseEntity<String> bean) {
        if (bean.getStatus().equals("200")) {
            //2：二维码过期
            //3：会议不在签到时间
            //88， 签到成功(状态码不固定)
            if (bean.getDatas() != null && bean.getDatas().size() > 0) {
                switch (bean.getDatas().get(0)) {
                    case "2":
                        errorDialog = new ClickOneDialog(this).builder().setContent("会议二维码已过期！")
                                .setCancelable(false).setCanceledOnTouchOutside(false);
                        errorDialog.setCallBack(new ClickOneDialog.ICallBack() {
                            @Override
                            public void sureCallback(String content) {
                                errorDialog.dismiss();
                            }
                        });
                        errorDialog.show();
                        break;
                    case "3":
                        errorDialog = new ClickOneDialog(this).builder().setContent("会议不在签到时间！")
                                .setCancelable(false).setCanceledOnTouchOutside(false);
                        errorDialog.setCallBack(new ClickOneDialog.ICallBack() {
                            @Override
                            public void sureCallback(String content) {
                                errorDialog.dismiss();
                            }
                        });
                        errorDialog.show();
                        break;
                    case "会议签到成功":
                        ViewInject.toast("签到成功");
                        btnSignIn.setText("已签到");
                        break;
                    default:
                        if (bean.getDatas().get(0).contains("会议")) {  //新版提示
                            errorDialog = new ClickOneDialog(this).builder().setContent(bean.getDatas().get(0))
                                    .setCancelable(false).setCanceledOnTouchOutside(false);
                            errorDialog.setCallBack(new ClickOneDialog.ICallBack() {
                                @Override
                                public void sureCallback(String content) {
                                    errorDialog.dismiss();
                                }
                            });
                            errorDialog.show();
                        } else {                                        //老版提示
                            ViewInject.toast("签到成功");
                            btnSignIn.setText("已签到");
                        }
                        break;
                }
            }
        } else {
            ViewInject.toast(bean.getMessage());
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case 1:
                    resultString = data.getStringExtra("resultString");
                    if (TextUtils.isEmpty(resultString)) {
                        ViewInject.toast("扫描失败,请重新尝试");
                        return;
                    }

                    String signMeetingId;
                    try {
                        signMeetingId = resultString.split(":", 2)[1].split(",")[0];
                    } catch (Exception e) {
                        ViewInject.toast("会议二维码错误,请重新尝试");
                        return;
                    }
                    signIn(signMeetingId);
                    break;
                case 201:
                    fileType = 1;
                    Uri uri = data.getData();//得到uri，后面就是将uri转化成file的过程。
                    img_path = GetPathFromUri4kitkat.getPath(this, uri);
                    presenter_upload.uploadFile(img_path);
                    break;
                case 202:
                    fileType = 2;
                    Uri uri_1 = data.getData();//得到uri，后面就是将uri转化成file的过程。
                    img_path = GetPathFromUri4kitkat.getPath(this, uri_1);
                    presenter_upload.uploadFile(img_path);
                    break;
            }
        } else if (resultCode == 100) {
            initP();
        }
    }

    /**
     * 签到
     */
    private void signIn(String signMeetingId) {
        if (!meetingId.equals(signMeetingId)) {
            errorDialog = new ClickOneDialog(this).builder().setContent("您所签到的会议不是当前会议！")
                    .setCancelable(false).setCanceledOnTouchOutside(false);
            errorDialog.setCallBack(new ClickOneDialog.ICallBack() {
                @Override
                public void sureCallback(String content) {
                    errorDialog.dismiss();
                }
            });
            errorDialog.show();
            return;
        }

        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        if (isNewMeeting) {
            params.put("qrCode", resultString);
            checkByQrCodePresenter.checkMeetingByQrCode(params);
        } else {
            params.put("meetingId", signMeetingId);
            presenter.getMeetingCheck(params);
        }
    }

    /**
     * 查询签到状态
     */
    private void inquireSignState() {
        Map<String, String> params = new HashMap<>();
        params.put("sessionUuid", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.SESSION_ID));
        params.put("meetingId", meetingId);
        presenter.getMeetingCheckState(params);
    }

    //从设备读取文件
    private void selectFile(int fileType) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        try {
            if (fileType == 1) {
                startActivityForResult(intent, 201);
            } else if (fileType == 2) {
                startActivityForResult(intent, 202);
            }
        } catch (ActivityNotFoundException ex) {
            new ToastDialog(this, "未找到文件管理应用，请安装文件管理应用后再试").show();
        }
    }

    @Override
    public void uploadDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                uploadDialog.setCanceledOnTouchOutside(false);
                uploadDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                uploadDialog.dismiss();
                ViewInject.toast("上传成功!");
                break;
        }
    }

    @Override
    public void updateFile(UploadBean uploadBean) {
        if (fileType == 1) {//会议材料
            if (fileMaterialAdapter == null) {
                fileMaterialAdapter = new MailFileAdapter(this, fileMaterialData, true);
                flvMaterial.setAdapter(fileMaterialAdapter);
            }
            uploadBean.getData().get(0).setFileUrl(img_path);
            fileMaterialData.add(uploadBean.getData().get(0));
            fileMaterialAdapter.notifyDataSetChanged();
        } else if (fileType == 2) {//会议纪要
            if (mailRecordAdapter == null) {
                mailRecordAdapter = new MailFileAdapter(this, mailRecordData, true);
                flvAttachment.setAdapter(mailRecordAdapter);
            }
            uploadBean.getData().get(0).setFileUrl(img_path);
            mailRecordData.add(uploadBean.getData().get(0));
            mailRecordAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void getFileData(MailFileBean mailFileBean) {
        if (mailFileBean.getStatus().equals("200")) {
            mailFileData.add(mailFileBean.getDatas().get(0));
            mailFileAdapter = new MailFileAdapter(aty, mailFileData, false);
            flvFile.setAdapter(mailFileAdapter);
        } else {
            Log.e("jx", "文件信息获取失败");
        }
    }

    @Override
    public void updateMeeting(BaseEntity<String> bean) {
        if (bean.getStatus().equals("200")) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast("保存失败");
        }
        loadingDialog.dismiss();
    }

    @Override
    public void updateStatus(BaseEntity<String> bean) {
        if (bean.getStatus().equals("200")) {
            ViewInject.toast("修改成功");
        } else {
            ViewInject.toast("修改失败");
        }
    }

    @Override
    public void createMeetingAbsence(BaseEntity<String> bean) {
        loadingDialog.dismiss();
        if (bean != null) {
            if (bean.getStatus().equals("200")) {
                ViewInject.toast("提交成功");
                llAbsenceContent.setVisibility(View.VISIBLE);
                llAbsenceContentEdt.setVisibility(View.GONE);
                tvAbsenceContent.setText(absenceContentEdt.getText().toString());
            } else {
                ViewInject.toast("提交失败");
            }
        }
    }

    @Override
    public void updateMeetingAbsence(BaseEntity<String> bean) {
    }
}
